import { ref } from "vue"
import { defineStore } from "pinia"
import { login } from "@/api/index"
import storage from "@/utils/storage"
type IuserInfo = {
    userCompanyId: number,
    userDeptId: number,
    userCompanyName: string,
    userDeptName: string,
    userId: number,
    userName: string,
    userPhone: string,
}

export const useUserStore = defineStore("user", () => {
    const userInfo = ref<IuserInfo | null>(null)
    const bhandUserInfo = ref<any>(null)

    const Rlogin = (data: any) => {
        return new Promise<void>(async (resolve, reject) => {
            login(data).then((res: any) => {
                if (res.code === 200) {
                    storage.set('token', res.data)
                    resolve(res)
                } else {
                    reject(res)
                }
            }).catch(err => {
                reject(JSON.stringify(err))
            })
        })
    }


    return { Rlogin, userInfo, bhandUserInfo };
})
// import { storeToRefs } from 'pinia';
// import { appStore } from '@/store/counterForSetup';
// // setup composition API模式
// const counterStoreForSetup = useCounterStoreForSetup();
// const { count } = storeToRefs(counterStoreForSetup);
// const { increment, doubleCount } = counterStoreForSetup;